/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - core
// Copyright (c) 2014.  All Rights Reserved
//
// File:		AESmartPtr.inl
// Author:		Gianluca Belardelli
// Date:		25/07/2013
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AESMARTPTR_INL_
#define _AESMARTPTR_INL_

template <class T>
AE_FORCEINLINE AESmartPtr<T>::AESmartPtr( void )
{
	m_lpPtr = NULL;
}

template <class T>
AE_FORCEINLINE AESmartPtr<T>::AESmartPtr( T *lpPtr )
{
	m_lpPtr = 0L;
	Set( lpPtr );
}

template <class T>
AE_FORCEINLINE AESmartPtr<T>::AESmartPtr( const AESmartPtr<T> &refPtr )
{
	m_lpPtr = 0L;
	Set( refPtr.GetPtr() );
}

template <class T>
AE_FORCEINLINE AESmartPtr<T>::~AESmartPtr( void )
{
	if( m_lpPtr )
		m_lpPtr->Release();
}

template <class T>
AE_FORCEINLINE AESmartPtr<T> &AESmartPtr<T>::operator=( const AESmartPtr<T> &refPtr )
{
	Set( refPtr.GetPtr() );
	return *this;
}

template <class T>
AE_FORCEINLINE AESmartPtr<T> &AESmartPtr<T>::operator=( T* lpPtr )
{
	Set( lpPtr );
	return *this;
}

template <class T>
AE_FORCEINLINE AESmartPtr<T>::operator T* () const
{
	return m_lpPtr;
}

template <class T>
AE_FORCEINLINE T* AESmartPtr<T>::operator->() const
{
	return m_lpPtr;
}

template <class T>
AE_FORCEINLINE T& AESmartPtr<T>::operator*()
{
	return *m_lpPtr;
}

template <class T>
AE_FORCEINLINE bool AESmartPtr<T>::operator == ( T* lpPtr ) const
{
	return ( m_lpPtr == lpPtr );
}

template <class T>
AE_FORCEINLINE bool AESmartPtr<T>::operator != ( T* lpPtr ) const
{
	return ( m_lpPtr != lpPtr );
}

template <class T>
AE_FORCEINLINE bool AESmartPtr<T>::operator == ( const AESmartPtr &refPtr ) const
{
	return ( m_lpPtr == refPtr.m_lpPtr );
}

template <class T>
AE_FORCEINLINE bool AESmartPtr<T>::operator != ( const AESmartPtr &refPtr ) const
{
	return ( m_lpPtr != refPtr.m_lpPtr );
}

template <class T>
AE_FORCEINLINE T* AESmartPtr<T>::GetPtr( void ) const
{
	return m_lpPtr;
}

template <class T>
AE_FORCEINLINE void AESmartPtr<T>::Set( T *lpPtr )
{
	if( m_lpPtr == lpPtr )
		return;

	T* lpOldPtr = m_lpPtr;
	m_lpPtr = lpPtr;

	if( lpPtr )
		lpPtr->AddRef();

	if( lpOldPtr )
		lpOldPtr->Release();
}

#endif // _AESMARTPTR_INL_
